//
//  GQRedPakageView.m
//  Puxiaowu
//
//  Created by kepuG on 17/1/13.
//  Copyright © 2017年 Nestpu. All rights reserved.
//

#import "GQRedPakageView.h"

#define pak_W (K_W*2/3)
#define pak_H (pak_W*0.7)
#define K_W [UIScreen mainScreen].bounds.size.width
#define K_H [UIScreen mainScreen].bounds.size.height


@interface GQRedPakageView ()

@property (strong ,nonatomic) UIView *firstPakageView;
@property (strong ,nonatomic) UIButton *cancelBtn;
@property (strong ,nonatomic) UIImageView *firPakageImage;
@property (strong ,nonatomic) UIButton *moneyBtn;

@property (nonatomic, strong, readonly) UIWindow *overlayWindow;

@end

@implementation GQRedPakageView




- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    
    if (self) {

    }
    
    self.firstPakageView = nil;
    self.firPakageImage = nil;
    return self;
}

-(void)loadSubView{
    
    [self.firstPakageView addSubview:self.firPakageImage];
    [self addSubview:self.firstPakageView];
}

-(UIView *)firstPakageView{
    
    if (_firstPakageView == nil) {
        
        _firstPakageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, K_W, K_H)];
        _firstPakageView.backgroundColor = [UIColor clearColor];
        _firstPakageView.alpha = 0.0;
        CGFloat pacX = (K_W-pak_W)/2.f;
        CGFloat pacY = (K_H-pak_H)/2.f;
        
        self.cancelBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        self.cancelBtn.frame = CGRectMake(pacX+pak_W +6, pacY - 20, 25, 25);
        [self.cancelBtn setBackgroundImage:[UIImage imageNamed:@"组-11"] forState:UIControlStateNormal];
        [self.cancelBtn addTarget:self action:@selector(cancelAction:) forControlEvents:UIControlEventTouchUpInside];
        
        [_firstPakageView addSubview:self.cancelBtn];
    }
    return _firstPakageView;
}


-(UIImageView *)firPakageImage{
    if (_firPakageImage == nil) {
        CGFloat pacX = (K_W-pak_W)/2.f;
        CGFloat pacY = (K_H-pak_H)/2.f;
        _firPakageImage = [[UIImageView alloc] initWithFrame:CGRectMake(pacX, pacY, pak_W, pak_H)];
        
        //  _firPakageImage.alpha = 1.0;
        _firPakageImage.image = [UIImage imageNamed:@"组-9"];
        _firPakageImage.userInteractionEnabled = YES;
        self.moneyBtn = [UIButton buttonWithType:UIButtonTypeSystem];
        self.moneyBtn.backgroundColor = [UIColor clearColor];
        self.moneyBtn.frame = CGRectMake(pak_W/3.f-3, pak_H*2/4.f, pak_W/3.f+3, pak_H/4.f+6);
        [self.moneyBtn addTarget:self action:@selector(getMoney:) forControlEvents:UIControlEventTouchUpInside];
        [_firPakageImage addSubview:self.moneyBtn];
    }
    return _firPakageImage;
}

+(void)showPakege{
    
    GQRedPakageView *package = [[GQRedPakageView alloc] initWithFrame:CGRectMake(0, 0, K_W, K_H)];
    
    [package loadSubView];
    UIWindow *window = [[UIApplication sharedApplication].windows lastObject];
    [window addSubview:package];
    [window makeKeyAndVisible];
}


-(void)cancelAction:(id)sender{
    
    NSLog(@"newView cancel");
}

-(void)getMoney:(id)sender{

    NSLog(@"newView getMoney");
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
